package com.cloud;

import javax.swing.*;
import javax.swing.tree.*;
import java.io.*;

public class Files 
{
	  JTree tree;
	  File f;
	  private String type;
	  DefaultMutableTreeNode root;
	   int count=0;
	  
	public File getf() {
		return f;
	}

	public void setf(File f) {
		this.f = f;
	}
	public String gettype() {
		return type;
	}

	public void settype(String type) {
		this.type = type;
	}
  
  public Files(File f, String type) 
  {
    root = new DefaultMutableTreeNode("root", true);   
    tree = new JTree(root);
    tree.setRootVisible(false);
    this.type=type;
    this.f=f;
  }

  
  public int getList(DefaultMutableTreeNode node, File f, String type) 
  {
	  
     if(!f.isDirectory()) 
     {
    	 if (f.getName().endsWith((type)))
          {
            //System.out.println("FILE  -  " + f.getName());
            count++;
            DefaultMutableTreeNode child = new DefaultMutableTreeNode(f);
            node.add(child);
            
           }
      }
     else 
     {
         //System.out.println("DIRECTORY  -  " + f.getName());
         DefaultMutableTreeNode child = new DefaultMutableTreeNode(f);
         node.add(child);
         File fList[] = f.listFiles();
         for(int i = 0; i  < fList.length; i++)
             getList(child, fList[i],type);
      }
     return count;
    }
  
  public int ReturnCount()
  {
	int total = getList(root,this.getf(), this.gettype());
	return total;
  }
}

